package org.birrap.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

@Entity
@Table(name = "BARES_T")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "BaresT.findAll", 
                query = "SELECT b FROM BaresT b"),
    @NamedQuery(name = "BaresT.findByIdBar", 
                query = "SELECT b FROM BaresT b WHERE b.idBar = :idBar"),
    @NamedQuery(name = "BaresT.findByNombre", 
                query = "SELECT b FROM BaresT b WHERE b.nombre = :nombre"),
    @NamedQuery(name = "BaresT.findByDireccion", 
                query = "SELECT b FROM BaresT b WHERE b.direccion = :direccion"),
    @NamedQuery(name = "BaresT.findByTelefono", 
                query = "SELECT b FROM BaresT b WHERE b.telefono = :telefono"),
    @NamedQuery(name = "BaresT.findByCodigoPostal", 
                query = "SELECT b FROM BaresT b WHERE b.codigoPostal = :codigoPostal"),
    @NamedQuery(name = "BaresT.findBaresConCervezas", 
                query = "SELECT b FROM BaresT b WHERE size(b.baresCervezasTapasVasosTCollection) <> 0 "),
    @NamedQuery(name = "BaresT.removeByIdBar",query = "DELETE FROM BaresT b WHERE b.idBar = :idBar")
})

@SequenceGenerator (name="SEQ_BARES_T" , sequenceName ="SEQ_BARES_T" , allocationSize = 1)
public class BaresT implements Serializable {
    @Basic(optional = false)
    @NotNull
    @Column(name = "CODIGO_POSTAL")
    private Integer codigoPostal;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "baresT")
    private Collection<BaresUsuarioT> baresUsuarioTCollection;
    @Size(max = 50)
    @Column(name = "FOTO")
    private String foto;
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @GeneratedValue (strategy = GenerationType.SEQUENCE, generator = "SEQ_BARES_T")
    @Column(name = "ID_BAR")
    private Integer idBar;
    
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 40)
    @Column(name = "NOMBRE")
    private String nombre;
    
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "DIRECCION")
    private String direccion;
    
    @Column(name = "TELEFONO")
    private Integer telefono;
    
    @Basic(optional = false)
    @Column(name = "LATITUD")
    private Double latitud;
    
    @Basic(optional = false)
    @Column(name = "LONGITUD")
    private Double longitud;
    
    @JoinTable(name = "BARES_USUARIO_T", joinColumns = {
        @JoinColumn(name = "ID_BAR", referencedColumnName = "ID_BAR")}, inverseJoinColumns = {
        @JoinColumn(name = "CORREO", referencedColumnName = "CORREO")})
    @ManyToMany
    private Collection<UsuariosT> usuariosTCollection;
    
    @JoinTable(name = "OFERTAS_BARES_T", joinColumns = {
        @JoinColumn(name = "ID_BAR", referencedColumnName = "ID_BAR")}, inverseJoinColumns = {
        @JoinColumn(name = "ID_OFERTA", referencedColumnName = "ID_OFERTA")})
    @ManyToMany
    private Collection<OfertasT> ofertasTCollection;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "baresT")
    private Collection<BaresCervezasTapasVasosT> baresCervezasTapasVasosTCollection;

    public BaresT() {
    }

    public BaresT(Integer idBar) {
        this.idBar = idBar;
    }

    public BaresT(Integer idBar, String nombre, String direccion, int codigoPostal, 
                  Double latitud, Double longitud) {
        this.idBar = idBar;
        this.nombre = nombre;
        this.direccion = direccion;
        this.codigoPostal = codigoPostal;
        this.latitud = latitud;
        this.longitud = longitud;
    }

    public Double getLatitud() {
        return latitud;
    }

    public void setLatitud(Double latitud) {
        this.latitud = latitud;
    }

    public Double getLongitud() {
        return longitud;
    }

    public void setLongitud(Double longitud) {
        this.longitud = longitud;
    }

    public Integer getIdBar() {
        return idBar;
    }

    public void setIdBar(Integer idBar) {
        this.idBar = idBar;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public String getDireccion() {
        return direccion;
    }

    public void setDireccion(String direccion) {
        this.direccion = direccion;
    }

    public Integer getTelefono() {
        return telefono;
    }

    public void setTelefono(Integer telefono) {
        this.telefono = telefono;
    }

    public Integer getCodigoPostal() {
        return codigoPostal;
    }

    public void setCodigoPostal(Integer codigoPostal) {
        this.codigoPostal = codigoPostal;
    }

    @XmlTransient
    public Collection<UsuariosT> getUsuariosTCollection() {
        return usuariosTCollection;
    }

    public void setUsuariosTCollection(Collection<UsuariosT> usuariosTCollection) {
        this.usuariosTCollection = usuariosTCollection;
    }

    @XmlTransient
    public Collection<OfertasT> getOfertasTCollection() {
        return ofertasTCollection;
    }

    public void setOfertasTCollection(Collection<OfertasT> ofertasTCollection) {
        this.ofertasTCollection = ofertasTCollection;
    }

    @XmlTransient
    public Collection<BaresCervezasTapasVasosT> getBaresCervezasTapasVasosTCollection() {
        return baresCervezasTapasVasosTCollection;
    }

    public void setBaresCervezasTapasVasosTCollection(Collection<BaresCervezasTapasVasosT> baresCervezasTapasVasosTCollection) {
        this.baresCervezasTapasVasosTCollection = baresCervezasTapasVasosTCollection;
    }
     

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idBar != null ? idBar.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof BaresT)) {
            return false;
        }
        BaresT other = (BaresT) object;
        if ((this.idBar == null && other.idBar != null) || (this.idBar != null && !this.idBar.equals(other.idBar))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.birrap.ejb.BaresT[ idBar=" + idBar + " ]";
    }

    public String getFoto() {
        return foto;
    }

    public void setFoto(String foto) {
        this.foto = foto;
    }

    @XmlTransient
    public Collection<BaresUsuarioT> getBaresUsuarioTCollection() {
        return baresUsuarioTCollection;
    }

    public void setBaresUsuarioTCollection(Collection<BaresUsuarioT> baresUsuarioTCollection) {
        this.baresUsuarioTCollection = baresUsuarioTCollection;
    }

    
}
